__author__ = 'Totomo'

print("="*30+"九九乘法表for第一版"+"="*30)
for n in range(1,10):
    for m in range(1,10):
        if m==n:
            # print(str(n) + "x" + str(m) + "=" + str((n * m)).ljust(2)) #m和n相等时换行
            print("{:<6}".format((str(n) + "x" + str(m) + "=" + str(n * m)))) #format输出
            break  #遍历到两个数相等时跳出循环，让乘法表不显示重复内容
        else:
            print(str(n) + "x" + str(m) + "=" + str(n * m).ljust(2),end="  ") #m和n不等时加空格隔开
print("="*30+"九九乘法表for第二版"+"="*30)
for n in range(9,0,-1):  #反向遍历n
    for m in range(1,10):
        if m==n:
            print(str(m) + "x" + str(n) + "=" + str(n * m).ljust(2))
            break
        else:
            print(str(m) + "x" + str(n) + "=" + str(n * m).ljust(2),end="  ")
print("="*30+"九九乘法表for第三版"+"="*30)
for n in range(1,10):
    for m in range(9,0,-1):  #反向遍历m
        if (n==m or n>m) and m!=1:
            print((str(m) + "x" + str(n) + "=" + str(n * m)).rjust(6),end="  ")
        elif m==1:
            print((str(m) + "x" + str(n) + "=" + str(n * m)).rjust(6)) #m逢1换行
        else:
            print("        ",end="")  #当n<=m且m!=1时加入空格使得乘法表向右对齐
print("="*30+"九九乘法表for第四版"+"="*30)
for n in range(9,0,-1):  #反向遍历n
    for m in range(9,0,-1):  #反向遍历m
        if (n==m or n>m) and m!=1:
            print((str(n) + "x" + str(m) + "=" + str(n * m)).rjust(6),end="  ")
        elif m==1:
            print((str(n) + "x" + str(m) + "=" + str(n * m)).rjust(6))
        else:
            print("        ",end="")